<?php


namespace app\api\model\wanlshop;


use fast\Http;

class TravelConnect
{
    protected $url = "http://develop4.webapi.travelconnect.co/";
    protected $CompanyId = 'TC0123';
    protected $SignKey = 'c509e77141e89c02ed3d7b8cfb0ad5a0';

    public function __construct()
    {

    }

    public function search($data){
        //$data = json_encode($data,JSON_UNESCAPED_UNICODE);
        $data = "{
	\"pageSize\": 10,
	\"pagenumber\": 1,
	\"lang\": \"zh-hk\",
	\"tripType\": \"2\",
	\"adult\": 1,
	\"child\": 1,
	\"infant\": 0,
	\"cabinClass\": 2,
	\"itinerary\": [{
			\"fromCity\": \"HKG\",
			\"toCity\": \"TPE\",
			\"depDate\": \"2022-05-01T00:00:00\",
			\"fromCityType\": 1,
			\"toCityType\": 1
		},
		{
			\"fromCity\": \"TPE\",
			\"toCity\": \"HKG\",
			\"depDate\": \"2022-05-07T00:00:00\",
			\"fromCityType\": 1,
			\"toCityType\": 1
		}
	],
	\"platformSource\": \"ReadyBook\",
	\"clientCurrency\": \"HKD\"

}";
        $method = 'api/flight/v2/search';
        $header =[
            'X-CompanyId:'.$this->CompanyId,
            'X-SignKey:'.$this->SignKey,
            'Content-Type:application/json'
        ];
       /* $params = Http::post($this->url.$method,$data,[
            CURLOPT_HTTPHEADER => $header,
        ]);*/
        $params = Http::post($this->url.$method,$data,[
            CURLOPT_HTTPHEADER => $header,
        ]);
        dump($params);exit;
    }

    public function test($data){
        $method = 'api/flight/v2/search';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->url.$method);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data,JSON_UNESCAPED_UNICODE));
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            'X-CompanyId:'.$this->CompanyId,
            'X-SignKey:'.$this->SignKey,
            'Content-Type:application/json'
        ]);
        $res = curl_exec($ch);
        curl_close($ch);

    }
}